package com.jz.cash.client.service.impl;

import com.jz.cash.client.entity.TableRecord;
import com.jz.cash.client.service.TableRecordService;
import com.jz.cash.client.states.DeleteState;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.List;

@Service
public class TableRecordServiceImpl extends BaseService<TableRecord, BaseExample, Long> implements TableRecordService {
    @Override
    public TableRecord findLatestRecord(Long id) {

        BaseExample example = new BaseExample();
        example.createCriteria().addCriterion("table_id=", id).addCriterion("mark_for_delete=", DeleteState.TRUE.getState());
        example.setOrderByClause(" created_date desc");
        List<TableRecord> tableRecords = selectByExample(example);
        if (!CollectionUtils.isEmpty(tableRecords)) {
            return tableRecords.get(0);
        }
        return null;
    }
}